package demo.day08

// Kotlin 继承与重载的open关键字
fun main() {
    println("<-----------父类-------------->")
    val person = Person("Ki")
    person.printInfo()
    println("<-----------子类-------------->")
    val student = Student("Qi")
    student.printInfo()
    println("<-----------父类接受子类-------------->")
    val person1:Person = Student("Ji")
    person1.printInfo()
    // 类型判断
//    println(person1 is Person)
//    println(person1 is Student)
    // is + as 配合使用
    if (person1 is Person){
        (person1 as Person).printInfo()
    }
}

// Kotlin所有的类 默认是final修饰的 不能被继承 和java相反
open class Person(val name:String){
    private fun showName() = "输入的名字为：${name}"
    open fun printInfo(){
        println(showName())
    }
}

class Student(val studentName:String) : Person(studentName){
    override fun printInfo() {
        println(showStudentName())
    }

    private fun showStudentName() = "子类的名字为：$studentName"
}